package cn.ctvonline.android.kaopu.fragment;

import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.transition.Fade;
import android.transition.TransitionManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.TextView;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.ctvonline.android.kaopu.R;
import cn.ctvonline.android.kaopu.activity.ImageShowActivity;
import cn.ctvonline.android.kaopu.activity.OrdinaryActivity;
import cn.ctvonline.android.kaopu.activity.PhotoAlbumActivity;
import cn.ctvonline.android.kaopu.activity.SwiperActivity;
import cn.ctvonline.android.kaopu.activity.demo.ActivitySwiperDemo;
import cn.ctvonline.android.kaopu.activity.demo.WaterDemoActivity;
import cn.ctvonline.android.kaopu.activity.frontpage.ChatActivity;
import cn.ctvonline.android.kaopu.base.BaseFragment;
import cn.ctvonline.android.kaopu.widget.view.WaterTextView;

/**
 * A placeholder fragment containing a simple view.
 */
public class FrontpageFragment extends BaseFragment {
    private View rootView;
    @Bind(R.id.main_tv1)
    TextView helloTv;
    @Bind(R.id.photo_tv)
    TextView photoAblumTv;
    @Bind(R.id.image_show_tv)
    TextView imageShowTv;
    @Bind(R.id.recycleview_show_tv)
    TextView recycleTv;
    @Bind(R.id.recycleview_chat_tv)
    TextView chatTv;
    @Bind(R.id.recyleview_water_tv)
    WaterTextView WaterTv;
    @Bind(R.id.recyleview_swipe_tv)
    TextView swipeTv;
    @Bind(R.id.recyleview_swipe_tv_two)
    TextView swipeTvTwo;
    @Bind(R.id.recyleview_base_activity_tv)
    TextView baseActivityTv;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        rootView = inflater.inflate(R.layout.fragment_frontpage, container, false);
        initViews();
        initListener();
        return rootView;
    }

    void initViews() {
        ButterKnife.bind(this, rootView);
        final Dialog alertDialog = new Dialog(getActivity(), R.style.ChooserDialogStyle);
        alertDialog.setContentView(R.layout.fenxiang);
        alertDialog.setCancelable(true);
        WindowManager.LayoutParams params = alertDialog.getWindow().getAttributes();
        params.width = WindowManager.LayoutParams.MATCH_PARENT;
        params.height = 600;
        alertDialog.getWindow().setAttributes(params);
        helloTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (v.isSelected()) {
                    v.setSelected(false);
                } else {
                    v.setSelected(true);
                }
            }
        });
    }

    public void initListener() {
        photoAblumTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(activity, PhotoAlbumActivity.class);
                activity.startActivity(intent);
            }
        });
        imageShowTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(activity, ImageShowActivity.class);
                activity.startActivity(intent);
            }
        });
        recycleTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                TransitionManager.beginDelayedTransition((ViewGroup) rootView, new Fade());
                Intent intent = new Intent(activity, PhotoAlbumActivity.class);
                activity.startActivity(intent);
            }
        });
        chatTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(activity, ChatActivity.class);
                activity.startActivity(intent);
            }
        });
        WaterTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(activity, WaterDemoActivity.class);
                activity.startActivity(intent);
            }
        });
        swipeTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(activity, SwiperActivity.class);
                activity.startActivity(intent);
            }
        });
        swipeTvTwo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(activity, ActivitySwiperDemo.class);
                activity.startActivity(intent);
                activity.overridePendingTransition(R.anim.push_in_right, R.anim.push_out_right);
            }
        });
        baseActivityTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(activity, OrdinaryActivity.class);
                activity.startActivity(intent);
            }
        });
    }
}
